package cst.a118lw.startproject_118lw.service;

import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;

import cst.a118lw.startproject_118lw.R;
import cst.a118lw.startproject_118lw.model.WeatherModel;

/**
 * Created by liang on 2017/5/7.
 */

public class MainActivity extends AppCompatActivity {
    private EditText city_edit;
    private Button btn_1;
    private TextView city_text;
    private TextView wd_text;
    private WeatherModel model;
    private WeatherListener Listener;
    @Override
    protected void omCreate(Bundle savedInstanceSttate){
        super.onCreate(savedInstanceSttate);
        setContentView(R.layout.activity_main);
        city_edit=(EditText) findViewById(R.id.city_edit);
        btn_1=(Button) findViewById(R.id.btn_1);
        city_text=(TextView) findViewById(R.id.city_text);
        wd_text=(TextView) findViewById(R.id.wd_text);
        Listener=new WeatherListener(){
            @Override
            public void onResponse(WeatherInfo w){
                city_text,setText(w.getCity());
                wd_text.setText(w.getTemp());
            }
            @Override
               public void  onFail(String msg){
                 city_text.setText("解析错误");
            }
        };


        btn_1.setOnClickListener(new View.OnClickListener()){
            @Override
                    public void onClick(View v){
                model = new WeatherModel();
                model.getWeatherModel(city_edit.getText().toString(),
                       Listener );
            }
    }

    }
}
